package top.riske.gen3d.DTO;

import com.tencentcloudapi.ai3d.v20250513.models.ViewImage;
import lombok.Data;
import top.riske.gen3d.enums.HunyuanInputImageViewTypeEnum;
import top.riske.gen3d.http.exception.BisException;

import java.util.List;
import java.util.Objects;

/**
 * 混元3D，图生3D,图片输入信息
 */
@Data
public class HunyuanInputMultiViewImagesDto {

    /**
     * 视角类型,从HunyuanInputImageViewTypeEnum中获取
     */
    private String viewType;

    /**
     * 视角图片链接
     */
    private String viewImageUrl;

    /**
     * 转换为腾讯云ViewImage数组，跳过前视角
     * @param hunyuanInputMultiViewImagesDtos 输入图片信息
     * @return ViewImage数组
     */
    public static ViewImage[] toViewImageArray(List<HunyuanInputMultiViewImagesDto> hunyuanInputMultiViewImagesDtos){
        ViewImage[] viewImages = new ViewImage[hunyuanInputMultiViewImagesDtos.size()-1];
        int index = 0;
        for (HunyuanInputMultiViewImagesDto image: hunyuanInputMultiViewImagesDtos) {
            // 跳过前视角
            if(Objects.equals(image.getViewType(), HunyuanInputImageViewTypeEnum.FONT.getValue())){
                continue;
            }
            viewImages[index] = toViewImage(image);
            ++index;
        }
        return viewImages;
    }

    /**
     * 转换为腾讯云ViewImage
     * @param hunyuanInputMultiViewImagesDto 输入图片信息
     * @return ViewImage
     */
    public static ViewImage toViewImage(HunyuanInputMultiViewImagesDto hunyuanInputMultiViewImagesDto){
        ViewImage viewImage = new ViewImage();
        viewImage.setViewType(hunyuanInputMultiViewImagesDto.getViewType());
        viewImage.setViewImageUrl(hunyuanInputMultiViewImagesDto.getViewImageUrl());
        return viewImage;
    }

    /**
     * 获取正视图图片
     * @param hunyuanInputMultiViewImagesDtos 输入图片信息
     * @return ViewImage
     */
    public static ViewImage findFrontViewImage(List<HunyuanInputMultiViewImagesDto> hunyuanInputMultiViewImagesDtos){
        for (HunyuanInputMultiViewImagesDto image: hunyuanInputMultiViewImagesDtos) {
            if(Objects.equals(image.getViewType(), HunyuanInputImageViewTypeEnum.FONT.getValue())){
                return HunyuanInputMultiViewImagesDto.toViewImage(image);
            }
        }
        throw new BisException("没有正视图图片");
    }

}
